package com.example.controller;


import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.entity.*;
import com.example.entity.others.Test_Map_Question;
import com.example.entity.others.Test_User_Other;
import com.example.entity.others.User_Question;
import com.example.entity.others.User_Subject;
import com.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    public TeacherService teacherService;

    //AI生成试卷
    //用ai生成试卷题目，一整个test实体和uid,生成到教师那边
    @PostMapping("/create/ai")
    public Result createAi(@RequestBody Test_User_Other testUser){
        teacherService.createAi(testUser);
        User_Subject userSubject = new User_Subject();
        userSubject.setSubject(testUser.getTest().getSubject());
        userSubject.setUid(testUser.getUser().getUid());
        return Result.success(teacherService.testList(userSubject));
    }

    //返回子女列表
    @PostMapping("/list/student")
    public Result listStudent(){
        return Result.success();
    }
    //添加子女
    @PostMapping("/bind")
    public Result bind(){
        return Result.success();
    }

    //返回教师试卷列表,需要uid
    @PostMapping("/test/list/teacher")
    public Result testList(@RequestBody(required = false) User_Subject userSubject){
        return Result.success(teacherService.testList(userSubject));
    }

    //返回教师的试卷的问题
    @PostMapping("/question/all/teacher")
    public Result questionAllParent(@RequestBody Test_User_Other testUserOther){
        return Result.success(teacherService.questionAllTeacher(testUserOther));
    }

    //删除教师指定试卷 需要uid，tid
    @PostMapping("/test/delete")
    public Result testDelete(@RequestBody Test_User testUser){
        return Result.success(teacherService.testDelete(testUser));
    }

    //人工组卷，生成试卷 需要test的tid和questionMap和user
    @PostMapping("/create/human")
    public Result createHuman(@RequestBody Test_Map_Question testMapQuestion){
        teacherService.createHuman(testMapQuestion);
        User_Subject userSubject = new User_Subject();
        userSubject.setSubject(testMapQuestion.getTest().getSubject());
        userSubject.setUid(testMapQuestion.getUser().getUid());
        return Result.success(teacherService.testList(userSubject));
    }
    //用户保存答案（只保存不批改）
    @PostMapping("/do/homework")
    public Result doHomework(@RequestBody List<Question_Teacher> questionTeachers){
        teacherService.doHomework(questionTeachers);
        return Result.success();
    }
    //创建班级 需要cid,teaid
    @PostMapping("/create/class")
    public Result joinClass(@RequestBody Class_Teacher classTeacher){
        return Result.success(teacherService.createClass(classTeacher));
    }
    //返回班级列表
    @PostMapping("/list/class")
    public Result listClass(@RequestBody Class_Teacher classTeacher){
        return Result.success(teacherService.listClass(classTeacher));
    }
    //退出班级 需要cid,sid,
    @PostMapping("/cancel/class")
    public Result cancelClass(@RequestBody Class_Teacher classTeacher){
        return Result.success(teacherService.cancelClass(classTeacher));
    }
    //返回学生指定学科的试卷标题
    @PostMapping("/test/list")
    public Result testListStudent(@RequestBody User_Subject userSubject){
        return Result.success(teacherService.testListStudent(userSubject));
    }
    //用户提交试卷之后自动批改 需要问题的id,content,answer,uanswer
    @PostMapping("/correcting/ai")
    public Result correctingAi(@RequestBody List<User_Question> userQuestions){
        return Result.success(teacherService.correctingAi(userQuestions));
    }
    //用户重置答案（只保存不批改）
    @PostMapping("/question/reset")
    public Result questionReset(@RequestBody JSONObject testUserOther){
        int tid = testUserOther.getInt("tid");
        int uid = testUserOther.getInt("uid");
        Test_User_Other testUserOther1 = new Test_User_Other();
        Test test = new Test();
        test.setTid(tid);
        User user = new User();
        user.setUid(uid);
        testUserOther1.setTest(test);
        testUserOther1.setUser(user);
        teacherService.questionReset(tid,uid);
        return Result.success(teacherService.questionAllTeacher(testUserOther1));
    }
    //分发试卷
    @PostMapping("/set/test")
    public Result SetTest(@RequestBody Test_User testUser){
        teacherService.setTest(testUser);
        return Result.success();
    }
    //生成单一学科做题情况分析 需要uid（用户的id），subject、cid
    @PostMapping("/create/analysis")
    public Result createAnalysisBySubject(@RequestBody Analysis_Teacher analysisTeacher){
        teacherService.createAnalysisBySubject(analysisTeacher);
        return Result.success(teacherService.getAnalysisAll(analysisTeacher));
    }
    //返回子女指定学科分析列表
    @PostMapping("/analysis/list")
    public Result analysisList(@RequestBody Analysis_Teacher analysisTeacher){
        return Result.success(teacherService.getAnalysisAll(analysisTeacher));
    }
    //删除指定分析
    @PostMapping("/delete/content")
    public Result DeleteAnalysisContent(@RequestBody Analysis_Teacher analysisTeacher){
        return Result.success(teacherService.deleteAnalysis(analysisTeacher));
    }
    //返回指定分析的内容
    @PostMapping("/get/content")
    public Result getAnalysisContent(@RequestBody Analysis_Teacher analysisTeacher){
        return Result.success(teacherService.getAnalysis(analysisTeacher));
    }
    //返回学生指定学科的试卷标题
    @PostMapping("/fault/list")
    public Result faultListStudent(@RequestBody JSONObject jsonObject){
        return Result.success(teacherService.faultListStudent(jsonObject));
    }
}
